from common.Utils import SHPDriver
from selenium.webdriver.common.by import By
import time
import ddddocr
#测试商城系统登录页面
class Login:
    def __init__(self):
        self.url="http://49.235.61.184/?s=user/loginInfo.html"
        self.driver=SHPDriver.driver
        self.driver.get(self.url)
    #验证码
    def captcha(self):
            ele = self.driver.find_element(By.XPATH, '//*[@id="form-verify-img"]')
            ele.screenshot('code.png')
            ele_bytes = ele.screenshot_as_png
            ocr = ddddocr.DdddOcr(show_ad=False)  # 关闭广告输出
            text = ocr.classification(ele_bytes)
            self.driver.find_element(By.XPATH, '//*[@type="text" and @name="verify"]').send_keys(text)
    #什么都不输就点击登录
    def LoginTest0(self):
        self.driver.find_element(By.XPATH, "//*[@type=\"submit\"]").click()
        SHPDriver.GetScreenShot()
    #错误的账号和错误的密码
    def LoginTest1(self):
            self.driver.find_element(By.XPATH, "//*[@name=\"accounts\"]").send_keys("bsgjksbkgsdb")
            self.driver.find_element(By.XPATH, "//*[@name=\"pwd\"]").send_keys("lkgslkg")
            self.driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/span[1]/button").click()
            self.captcha()
            self.driver.find_element(By.XPATH, "//*[@type=\"submit\"]").click()
            #添加屏幕截图
            SHPDriver.GetScreenShot()
            #清空账号密码
            self.driver.find_element(By.XPATH, "//*[@name=\"accounts\"]").clear()
            self.driver.find_element(By.XPATH, "//*[@name=\"pwd\"]").clear()
    #正确的账号和错误的密码
    def LoginTest2(self):
            self.driver.find_element(By.XPATH, "//*[@name=\"accounts\"]").send_keys("zzz111")
            self.driver.find_element(By.XPATH, "//*[@name=\"pwd\"]").send_keys("lkgslkg")
            self.driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/span[1]/button").click()
            self.captcha()
            self.driver.find_element(By.XPATH, "//*[@type=\"submit\"]").click()
            #添加屏幕截图
            SHPDriver.GetScreenShot()
            #清空账号密码
            self.driver.find_element(By.XPATH, "//*[@name=\"accounts\"]").clear()
            self.driver.find_element(By.XPATH, "//*[@name=\"pwd\"]").clear()
    #成功登录
    def LoginTest3(self):
        self.driver.find_element(By.XPATH,"//*[@name=\"accounts\"]").send_keys("zzz111")
        self.driver.find_element(By.XPATH,"//*[@name=\"pwd\"]").send_keys("zzz123")
        self.captcha()
        self.driver.find_element(By.XPATH,"//*[@type=\"submit\"]").click()
        time.sleep(2)
        #添加屏幕截图
        SHPDriver.GetScreenShot()
Test=Login()
Test.LoginTest0()
Test.LoginTest1()
Test.LoginTest2()
Test.LoginTest3()
